package com.example.qq.Vm;

import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

import com.example.qq.R;
import com.example.qq.bean.Msg;

import java.util.ArrayList;
import java.util.List;

public class MsgVm extends ViewModel {
    public MutableLiveData<List<Msg>> msgList = new MutableLiveData();

    public List<Msg> getMsgList() {
        if (msgList.getValue() == null) {
            ArrayList list = new ArrayList();
            msgList.setValue(list);
        }
        return msgList.getValue();
    }

    public void init() {
        //模拟进行网络请求，获取消息列表
        ArrayList<Msg> msgs = new ArrayList();
        msgs.add(new Msg(R.mipmap.ic_launcher, "hello", "Title1"));
        msgs.add(new Msg(R.mipmap.ic_launcher, "hello", "Title2"));
        msgs.add(new Msg(R.mipmap.ic_launcher, "hello", "Title3"));
        msgs.add(new Msg(R.mipmap.ic_launcher, "hello", "Title4"));
        msgs.add(new Msg(R.mipmap.ic_launcher, "hello", "Title5"));
        msgs.add(new Msg(R.mipmap.ic_launcher, "hello", "Title6"));
        msgList.setValue(msgs);
    }
}
